package com.evola.rm.utils
{
	import mx.utils.StringUtil;

	public class StringUtils
	{

		public static function trimLeft(str:String):String
		{
			if (str == null)
				return '';

			var startIndex:int=0;
			while (StringUtil.isWhitespace(str.charAt(startIndex)))
				++startIndex;

			var endIndex:int=str.length - 1;
			while (isNewLine(str.charAt(endIndex)))
				--endIndex;

			if (endIndex >= startIndex)
				return str.slice(startIndex, endIndex + 1);
			else
				return "";
		}

		private static function isNewLine(character:String):Boolean
		{
			switch (character)
			{
				case "\r":
				case "\n":
				case "\f":
					return true;

				default:
					return false;
			}
		}

		public static function isAllWhitespace(value:String):Boolean
		{
			if (!value)
				return true;

			var startIndex:int=0;
			while (StringUtil.isWhitespace(value.charAt(startIndex)))
				++startIndex;

			if (startIndex == value.length)
				return true;

			return false;
		}
	}
}
